map={

        map: null,
        baseLayer: null,
        vectorLayer: null,
        resolutions: [0.000029142662625000022,
                      0.000014571331312500011,
                      0.0000072856656562500055,
                      0.0000036428328281250027,
                      0.0000018214164140625014],
		init : function(divId, name, features,selectedId){
			if(this.map == null){
				var maxExtent = new OpenLayers.Bounds(-2.7019824077579,42.828246925505,-2.6422982347019,42.869917329965);
				this.map = new OpenLayers.Map({projection:'EPSG:4326',resolutions: this.resolutions, maxExtent: maxExtent, restrictedExtent: maxExtent} );
	            this.baseLayer = new OpenLayers.Layer.WMS( "Geouskadi WMS",
	            		"http://euskadi.stereowebmap.com/SgdWmsEuskadi.dll/WMS", {layers: 'EUSKADI2012', srs:'EPSG:4326'} );
	            this.map.render(divId);
	            
	            var portales = new OpenLayers.Layer.WMS( "Portales",
	            		"http://www.geo.euskadi.net/WMS_CARTOGRAFIA", {layers: '15', transparent:true,format:'image/png'} );
	            var calles = new OpenLayers.Layer.WMS( "Calles",
	            		"http://www.geo.euskadi.net/WMS_CARTOGRAFIA", {layers: '16', transparent:true,format:'image/png'} );
	            
	            
	            this.vectorLayer = new OpenLayers.Layer.Vector(name);
	            
	            var mapFeatures = new Array();
	            for(var i=0; i< features.length; i++){
	            	var feature=features[i];
	            	mapFeatures.push(this.createMapFeature(feature));
	            }
	            this.vectorLayer.addFeatures(mapFeatures);
	            this.map.addControl(new OpenLayers.Control.MousePosition());
	            
	            this.map.addLayer(this.baseLayer);
	            this.map.addLayer(calles);
	            this.map.addLayer(portales);
	            this.map.addLayer(this.vectorLayer);
	            
	           this.map.zoomTo(1);
	            
	            if(selectedId != null){
	            	for(var i = 0; i<this.vectorLayer.features.length; i++){
	            		if(selectedId == this.vectorLayer.features[i].attributes.id){
	            			var f = this.vectorLayer.features[i];
	            			this.map.setCenter(new OpenLayers.LonLat(f.geometry.x,f.geometry.y), 2, false, false);
	            		}
	            	}
	            }
			}
			else{
				this.updateFeatures(features);
			}
		},
		
		
		
		updateFeatures: function(features){
			this.vectorLayer.removeAllFeatures();
			var mapFeatures = new Array();
            for(var i=0; i< features.length; i++){
            	var feature=features[i];
            	mapFeatures.push(this.createMapFeature(feature));
            }
            this.vectorLayer.addFeatures(mapFeatures);
		},
		
		createMapFeature: function(feature){
			var location = feature.location;
			location = location.replace('POINT(','');
			location = location.replace(')','');
			location = location.split(' ');
			var x = location[0];
			var y = location[1];
			var markerStyle = {externalGraphic: feature.icon, graphicWidth: 48, graphicHeight: 48, graphicYOffset: -16, graphicOpacity: 1};
			var featureMap = new OpenLayers.Feature.Vector(
                new OpenLayers.Geometry.Point(x,y), {}, markerStyle
            );
			featureMap.attributes = feature;
			return featureMap;
		}
};